package org.ielts.service;

import java.util.List;

import org.ielts.domain.base.Student;
import org.ielts.domain.security.User;
import org.ielts.repository.StudentRepository;
import org.ielts.repository.security.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TutorService {
	@Autowired
	UserRepository userRepository;

	@Autowired
	StudentRepository studentRepository;

	@Transactional
	public Iterable<User> listTutor() {
		String role = "学习顾问";
		Iterable<User> users = userRepository.findByRoleName(role);
		return users;
	}

	@Transactional
	public Page<Student> listMyStudent(String uid, Pageable pageable) {
		List<Student> sts = studentRepository.findStudentByTutorId(uid, pageable);
		Page<Student> p = new PageImpl<Student>(sts, pageable, studentRepository.countByTutorId(uid));
		return p;
	}

}
